//
//  MZTabBarVC.m
//  minzu
//
//  Created by mac1 on 2025/7/3.
//

#import "MZTabBarVC.h"

@interface MZTabBarVC ()

@end

@implementation MZTabBarVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor redColor];
    [self addVC];
}
-(void)addVC{
    
    UIViewController *vc1 =  [self makeChildView:@"DZHomeVC" title:@"首页" imageName:@"" selImageName:@""];
    UIViewController *vc2 =  [self makeChildView:@"DZMeVC" title:@"我的" imageName:@"" selImageName:@""];
    self.viewControllers = @[vc1, vc2];
    
    self.tabBar.tintColor = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0];
    self.tabBar.unselectedItemTintColor = [UIColor colorWithRed:153/255.0 green:153/255.0 blue:153/255.0 alpha:1.0];
    UITabBarItem *item = [UITabBarItem appearance];
    item.titlePositionAdjustment = UIOffsetMake(0, -2);
    [item setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:11]} forState:UIControlStateNormal];
    [item setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:11]} forState:UIControlStateSelected];
    
    UITabBarAppearance * appearance = [[UITabBarAppearance alloc] init];
    appearance.backgroundColor = [UIColor whiteColor];
    self.tabBar.standardAppearance = appearance;
    if (@available(iOS 15.0, *)) {
        self.tabBar.scrollEdgeAppearance = appearance;
    }

    // 设置标签栏的主题"改文字颜色"
    self.view.backgroundColor=[UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1];
    // 让标签栏也没有透明效果,会影响子控件的view的大小,如果没有透明效果后子控件的view是到tabBar上面
    self.tabBar.translucent = NO;
}
- (UIViewController *)makeChildView:(NSString *)className title:(NSString *)title imageName:(NSString *)imageName selImageName:(NSString *)selImageName{
    // 1.把字符串的转换成类
    Class class = NSClassFromString(className);
    // 2.创建子控件
    UIViewController *vc = [[class alloc] init];
    // 3.标签栏上的文字
    vc.tabBarItem.title = title;
    // 4.设置标签栏上的默认图片
    vc.tabBarItem.image=[[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    // 5.拼接选中状态的图片名称
    
    // 6.设置标签栏上的选中状态的图片
    vc.tabBarItem.selectedImage = [[UIImage imageNamed:selImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    // 创建导航控制器并给导航控制器添加根控制器
    MZNavigationVC *nav = [[MZNavigationVC alloc] initWithRootViewController:vc];
    // 给控制器设置标题后,如果它里面有导航条也有标签栏时,那这个标签会影响导航条和标签栏上的文字
    vc.title = title;
    // 返回导航控制器
    return nav;
}

@end
